package program

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/v2/assignments/\\d+/quizzes/\\d+')),
                producer('/api/v2/assignments/1/quizzes/1'))
        headers {
            contentType(applicationJsonUtf8())
            header('id', 1)
        }
    }
    response {
        status(200)
        headers {
            contentType(applicationJsonUtf8())
        }
        body("""
        {
            "id":1,
            "description":"subjective1",
            "makerId":1,
            "referenceNumber":1,
            "isAvailable":true,
            "quizGroupId":1,
            "createTime":"2018-09-12 06:00:00.0",
            "updateTime":"2018-09-12 06:00:00.0",
            "remark":"remark1",
            "tags":[],
            "userAnswer":"",
            "answerBranch":""
        }
        """)
        bodyMatchers {
            jsonPath('$', byType())
            jsonPath('$.id', byRegex(number()))
            jsonPath('$.description', byRegex("[\\s\\S]+"))
            jsonPath('$.makerId', byRegex(number()))
            jsonPath('$.referenceNumber', byRegex(number()))
            jsonPath('$.isAvailable', byRegex(anyBoolean()))
            jsonPath('$.quizGroupId', byRegex(number()))
            jsonPath('$.createTime', byRegex("[\\s\\S]+"))
            jsonPath('$.updateTime', byRegex("[\\s\\S]+"))
            jsonPath('$.remark', byRegex("[\\s\\S]+"))
            jsonPath('$.tags', byType())
            jsonPath('$.userAnswer', byType())
            jsonPath('$.answerBranch', byType())
        }
    }

}